<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>找回密码</title>
    <link rel="stylesheet" href="css/reset.css" />
    <link rel="stylesheet" href="css/all.css" />
    <script src="js/jquery-1.7.1.min.js"></script>
    <!--<script src="js/PIE.js"></script>-->
    <!--<script src="js/self.js"></script>-->
    <style>
        body{
            width: 100%;
            height: 100%;
            background: transparent;
        }
    </style>
</head>
</body ontouchstart="">

<div class="loginBlock of bcf w100 h100">
    <div class="logintittle of tc pr">
        找回密码 <span class="pa cursor" id="close-x">&times;</span>
    </div>
    <div class="of jz" style="width: 454px;">
        <input type="text" name="" id="tel" placeholder="手机号码" class="db br3 jz br3" style="margin-top: 72px;"/>
        <p class="t2 cred f14"></p>
        <div class="clearfix of">
            <input type="text" name="" id="imgVerificationCode" placeholder="图形验证码" class="db br3 fl" style="width: 200px;"/>
            <img src="images/tupianma.jpg" class="fr">
        </div>
        <p class="t2 cred f14"></p>
        <div class="clearfix of">
            <input type="text" name="" id="telVerificationCode" placeholder="短信验证码" class="db br3 fl" style="width: 200px;"/>
            <input type="button" value="获取验证码" name="" id="VerificationCodeBtn"  onclick="settime($('#VerificationCodeBtn'),$('#tel'))" class="cursor tc cf fr db f18"/>
        </div>
        <p class="t2 cred f14"></p>
        <input type="password" name="" id="pwd" placeholder="新密码" class="db br3"/>
        <p class="t2 cred f14"></p>
        <input type="password" name="" id="pwdrepetition" placeholder="重复密码" class="db br3"/>
        <p class="t2 cred f14"></p>

        <div class="clearfix of" style="margin-top: 46px;">
            <input type="button" value="确定找回" name="" id="loginSub" class="cursor tc cf fl db" onclick="Sub();"/>
            <span id="goLogin" class="fl f17 aht cursor" style="color: #1e83f3;margin-left: 30px;margin-top: 39px">记起密码?去登陆</span>
        </div>
    </div>
</div><!--loginBlock-->
<div id="loadingfDiv" class="loadingfDiv pf w100 h100 db">
    <div class="w100 h100">
        <img src="images/loading.gif" class="db jz" style="margin-top: 40%;">
    </div>
</div><!--loadinfDiv-->


<script>

    $(window).on("load", function() {
        $("#close-x,#goLogin").click(function () {
            $("#forgotPwdIframeDiv", parent.document).slideUp();
            $(".theme-popover-mask", parent.document).fadeOut();

        })
        $("#goLogin").click(function () {
            $("#loginIframeDiv", parent.document).slideDown(1000);
            $(".theme-popover-mask", parent.document).fadeIn(1000);

        })
    })
    //倒计时
    var countdown=60;
    function resetCode(btn) {
        console.log('倒计时');
        if (countdown == 0) {
            btn.removeAttr("disabled");
            btn.val("重新获取验证码");
            countdown = 60;
            return;

        } else {
            btn.attr("disabled", "disabled");
            btn.val("请在" + countdown + "s内填写");
            countdown--;
        }
        setTimeout(function() { resetCode(btn); },1000);
    }

    //发送验证码
    function smsSend(tel) {
        var phone =$.trim(tel);
        $.ajax({
            url: "",
            data: {"mobile": phone},
            type: 'get',
            dataType: 'json',
            beforeSend: function () {
            },
            success: function (data) {
                console.log(data);
                if (data.code == 200) {
                    alert('验证码发送成功,请注意查收!');
                } else {
                    alert(data.msg);
                }
            },
            error: function () {
                alert(data.msg);
                alert('网络忙，请重试');
            },
            complete: function () {
            }
        });
    }

    //验证手机号码
    function checkPhone(tel) {
        var pattern = /^1[0-9]{10}$/;
        var phone =$.trim(tel);
        console.log(phone);
        isPhone = 1;
        if (phone == '') {
            $('#tel').next('p').text('你还未填写联系电话');
            isPhone = 0;
            return false;
        }
        if (!pattern.test(phone)) {
            $('#tel').next('p').text('手机号填写的格式不对，请正确填写');
            isPhone = 0;
            return false;
        }
        if(pattern.test(phone)){
            return true;
        }

    }
    /*获取验证码*/
    var isPhone = 1;
    function settime(btn,tel){
        var phone= tel.val();
        if(checkPhone(phone)){
            resetCode(btn); //倒计时
            smsSend(phone);
        }else{
            tel.focus();
        }
    }

    function Sub() {
        var tel =$.trim($('#tel').val());
        var imgVerificationCode = $.trim($('#imgVerificationCode').val());
        var telVerificationCode = $.trim($('#telVerificationCode').val());
        var pwd = $.trim($('#pwd').val());
        var pwdrepetition = $.trim($('#pwdrepetition').val());

        if(tel== ""){
            $('#tel').next('p').text('你还未填写联系电话');
            return false;
        }else if (tel != ""&&!(/^((\d{3}-\d{8}|\d{4}-\d{7,8})|(1[3|5|7|8][0-9]{9}))$/.test(tel))) {
            $('#tel').next('p').text('手机号填写的格式不对，请正确填写');
            return false;
        }else {
            $('#tel').next('p').text(' ');
        }

        if(imgVerificationCode ==""){
            $('#imgVerificationCode').parent('div').next('p').text('你还未填写图形验证码');
            return false;
        }
        if(!(imgVerificationCode =="")){
            $('#imgVerificationCode').parent('div').next('p').text(' ');
        }
        if(telVerificationCode ==""){
            $('#telVerificationCode').parent('div').next('p').text('你还未填写手机验证码');
            return false;
        }
        if(!(telVerificationCode =="")){
            $('#telVerificationCode').parent('div').next('p').text(' ');
        }
        if(pwd == ""){
            $('#pwd').next('p').text('你还未填写密码');
            return false;
        }
        if(!(pwd == "")){
            $('#pwd').next('p').text(' ');
        }
        if(pwdrepetition== " "){
            $('#pwdrepetition').next('p').text('你还未填写密码');
            return false;
        }
        if(!(pwdrepetition== " ")){
            $('#pwdrepetition').next('p').text(' ');
        }
        if(pwdrepetition!=pwd){
            $('#pwdrepetition').next('p').text('两次输入的密码不一样');
            return false;
        }
        if(pwdrepetition==pwd){
            $('#pwdrepetition').next('p').text(' ');
        }

        $.ajax({
            url: "",
            data: {tel:tel,pwd:pwdrepetition,imgVerificationCode:imgVerificationCode,telVerificationCode:telVerificationCode},
            type: 'post',
            dataType: 'json',
            beforeSend: function () {
                $("#loadingfDiv").fadeIn();
            },
            success: function (data) {
                console.log(data);
                if (data.code == 200) {
//                        alert("您的申请已提交,等待审核");
//                        alert(data.msg);
//                        window.location.reload();
//                        location.href = "withdraw.html";
                }else{
//                        alert(data.msg);
                    //window.history.back(-1);
                }
            },
            error: function (data) {
                alert(data.msg);
                return false;
            },
            complete: function () {
                $("#loadingfDiv").fadeOut();
                $("#close-x").trigger('click');
            }
        });
    }
</script>
</body>
</html>